/**
 * 
 */
package com.icbc.cfsmgmt.common.productfile;

import com.alibaba.fastjson.JSONObject;
import com.icbc.cc.api.ApiCommonUtils;
import com.icbc.common.fileupload.IdUtil;
import com.icbc.cte.base.TranFailException;
import com.icbc.ctp.core.IContext;
import com.icbc.ctp.core.annotations.Input;
import com.icbc.ctp.core.annotations.Output;
import com.icbc.ctp.core.impl.OperationStep;

/**
 * TODO 类的描述：。 
 * <pre>
 *
 * </pre>
 *
 * <pre>
 * modify by lenovo on 2016-3-23
 *    fix->1.
 *         2.
 * </pre> 
 */
@Input(name = {"id","prodid","prodname","type","httppath","filepath","filename"}, 
		type = {"java:java.lang.String","java:java.lang.String","java:java.lang.String","java:java.lang.String","java:java.lang.String","java:java.lang.String","java:java.lang.String"}, 
		mustInput = {true,true,true,true,true,true,true}, 
		isVariable = {true,true,true,true,true,true,true}, 
		isArray = {false,false,false,false,false,false,false}, 
		description = {"产品资料id","产品编号","产品名称","资料类型","相对地址","绝对地址","资料名称"})
@Output(name = { "retCode"}, type = { "java:java.lang.String"}, isArray = { false}, description = {
		"返回标志"})
public class AddProductFiles extends OperationStep {
	
	
	/* (non-Javadoc)
	 * @see com.icbc.ctp.core.impl.OperationStep#execute(com.icbc.ctp.core.IContext)
	 */
	@Override
	protected int execute(IContext context) throws TranFailException {
		// TODO Auto-generated method stub
		try{
			String id= (String)getInputValue(context,"id");
			String prodid= (String)getInputValue(context,"prodid");
			String prodname= (String)getInputValue(context,"prodname");
			String type= (String)getInputValue(context,"type");
			String httppath= (String)getInputValue(context,"httppath");
			String filepath= (String)getInputValue(context,"filepath");
			String filename= (String)getInputValue(context,"filename");
			
			//------------------------------------PPT------------------------------------------
			if(id==null || "".equals(id)){
				JSONObject pptJson=new JSONObject();
				pptJson.put("prodid", prodid);
				pptJson.put("prodname", prodname);
				pptJson.put("type", type);
				pptJson.put("httppath", httppath);
				
				pptJson.put("realpath", filepath);
				pptJson.put("filename", filename);
				pptJson.put("filetype", filename.substring(filename.lastIndexOf(".")+1,filename.length()));
				pptJson.put("fileId", IdUtil.getRandomStr());
				
				String 	result = ApiCommonUtils.excuteOp(pptJson.toJSONString(), "addproductfiles");
				JSONObject newobj=JSONObject.parseObject(result);
			}else{
				JSONObject pptJson=new JSONObject();
				pptJson.put("optionId", id);
				pptJson.put("prodid", prodid);
				pptJson.put("prodname", prodname);
				pptJson.put("type", type);
				pptJson.put("httppath", httppath);
				
				pptJson.put("realpath", filepath);
				pptJson.put("filename", filename);
				pptJson.put("fileType", filename.substring(filename.lastIndexOf(".")+1,filename.length()));
				pptJson.put("fileId", IdUtil.getRandomStr());
				
				String 	result = ApiCommonUtils.excuteOp(pptJson.toJSONString(), "editproductfiles");
				JSONObject newobj=JSONObject.parseObject(result);
			}
			
			
			
			
			context.setValueAt("retCode", 0);
			
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e);
			context.setValueAt("retCode", -1);
		}
		return 0;
	}

}
